const data = {
	'颜色': ['红色', '黄色', '绿色'],
	'尺码': ['L', 'XL', 'XXL'],
	'大小': ['小', '中', '大'],
}
const list = [
	['红色', '黄色', '绿色'],
	['L', 'XL', 'XXL'],
	['小', '中', '大'],
]

// export const dealSpec = (list) => {
// 	let arr = []
// 	list.forEach(item => {
// 		for (let key in item) {
// 			if (!arr[key]) {
// 				arr[key] = []
// 			}
// 			arr[key].push(item[key])
// 		}
// 	})
// 	return arr
// }

const combine = (arr) => {
	let r = [];
	(function f(t, a, n) {
		if (n == 0) return r.push(t);
		for (var i = 0; i < a[n - 1].length; i++) {
			f(t.concat(a[n - 1][i]), a, n - 1);
		}
	})([], arr, arr.length);
	return r;
}

const dealWithSpec = () => {
	const res = combine(list)
	console.log(res);
	let list1 = []
	res.forEach(item => {
		item.forEach(item1 => {
			for (let key in data) {
				const arr = data[key].some(item2 => item2 === item1)
				if (arr) list1.push(`${key}:${item1}`)
			}
		})
	})
	let arr = list1.map((item, index) => {
		if (index % 3 === 2) item = `${item}-`
		return item
	})
	let arr1 = arr.join(',').split('-,').map((item, index) => {
		if (index === arr.join(',').split('-,').length - 1) {
			item = item.split('-')[0]
		}
		let data = item.split(',').map(item1 => {
			return item1.split(':')
		})
		let obj = {}
		data.forEach(item2 => {
			obj[item2[0]] = item2[1]
		})
		return {
			spec: JSON.stringify(obj),
			price: 10,
			num: 10,
			img: '111.png'
		}
	})
	// console.log(arr1);
}


// dealWithSpec()
